package m.jclecai.com.adapter.independentLotteryAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import m.jclecai.com.R;
import m.jclecai.com.bean.MissDataBean;

/**
 * Created by lenovo on 2017/6/14.
 * <p>
 * //双色球页面内开奖结果
 *
 * 双色球、大乐透、七乐彩
 */

public class SSQ_DLT_QLC_LotteryAdapter extends BaseAdapter {

    private final Context context;
    private List<MissDataBean.Codes> codes;

    public SSQ_DLT_QLC_LotteryAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<MissDataBean.Codes> codes) {
        if(codes == null) codes = new ArrayList<>();
        this.codes = codes;
    }


    @Override
    public int getCount() {
        return codes.size();
    }

    @Override
    public Object getItem(int position) {
        return codes.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.independent_lottery_base_item, null);
            holder.ll_item = (LinearLayout) convertView.findViewById(R.id.ll_item);
            holder.tv_term = (TextView) convertView.findViewById(R.id.tv_term);
            holder.tv_red_code = (TextView) convertView.findViewById(R.id.tv_red_code);
            holder.tv_blue_code = (TextView) convertView.findViewById(R.id.tv_blue_code);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (position % 2 == 0) {
            holder.ll_item.setBackgroundResource(R.color.LotteryBg);
        } else {
            holder.ll_item.setBackgroundResource(R.color.white);
        }

        MissDataBean.Codes code = this.codes.get(position);
        String issue = code.getIssue();
        String substring = issue.substring(issue.length() - 2, issue.length());
        holder.tv_term.setText(substring + "期");

        String[] split = code.getCode().split("\\|");
        holder.tv_red_code.setText(split[0]);
        holder.tv_blue_code.setText(split[1]);


        return convertView;
    }

    private class ViewHolder {
        LinearLayout ll_item;
        TextView tv_term;
        TextView tv_red_code;
        TextView tv_blue_code;
    }
}
